- /* sdfd2dbl.cpp by K.Tsuru */
- // function ID 3001
- /********************************************************************
- SDouble class
- Provides a conversion SDouble --> double.
- If you let err = 0, an out of range of double does not terminate the
- program and return DBL_MAX or 0.0. The error (OVERFLOW_ERR or UNDERFLOW_ERR)
- can be detected by SNError().
- Default value is declared as err = 1.
- *********************************************************************/
- #ifndef SN_H
- #include "sn.h"
- #endif
-
- static const char* func = "doubleD";
- double doubleD(const SDouble& sd, int err){
- if(sd.Type() != sd.REAL) SNManager::SetError(sd.RADIX_ERR, func, 3001);
- if(sd.SNSign() == 0) return 0.0;
-
- // detect error
- long de = sd.DExp();
- SNManager::SNErrorFlag error = sd.NO_ERR;
- double d = 0.0;
-
- if(de > DBL_MAX_10_EXP-1){
- error = sd.OVERFLOW_ERR;
- d = DBL_MAX;
- }else if( de < DBL_MIN_10_EXP+1 ){
- error = sd.UNDERFLOW_ERR;
- d = 0.0;
- }
-
- if(error != sd.NO_ERR){
- if(err) sd.SetError(error, func, 3001);
- else sd.SetErrorFlag(error);
- return d;
- }
-
- RealSize C;
- //To get fifteen figures in double it needs
- // 0.000x yyyy zzzz aaaa bbbb HHHH(hidden) .... six figures
- uint fig = DOUBLE_FIG/DFIGURES +3u;
- SDouble x;
- x = sd.TakeOutFigures(fig+2u);
- x.StdReform(3001);
- C.SetEffFig(fig);
- x.Round(x.STD_REF | x.CUR_MAX); // round off
- C.SetEffFig(0);
-
- uint i = x.First(), last = x.Last();
- double qpowFig = dpow10(-DFIGURES), eps = dpow10(-DOUBLE_FIG-DFIGURES);
- double r = qpowFig;
- d = x[i++]; //d have one figure at least.
- for( ; (i <= last) && (r > eps) ; i++){
- d += (double)x[i]*r;
- r *= qpowFig;
- }
- //multiply by D^e
- int e = x.NetRdxExp()-1;
- d *= pow((double)DRADIX, (double)e);
-
- return (x.Sign(3001) > 0) ? d : -d;
- }
-
sdfd2dbl.cpp : last modifiled at 2008/12/15 14:41:56(1,802 bytes)
created at 2017/10/07 10:22:50
The creation time of this html file is 2017/10/07 11:29:39 (Sat Oct 07 11:29:39 2017).